<?php

class Helper_Authform
{
    public $view;
    
    public function setView(Zend_View_Interface $view)
    {
        $this->view = $view;
    }

    function authform($forceDisplay=false)
    {
        $output='';
        
        $user=Zend_Registry::get('user');
            
        if (!$user->isRegistered())   
        {     
            if (!Zend_Registry::get('config')->user->quickAuthForm && !$forceDisplay) return ;
            
            if (Zend_Registry::isRegistered('authForm'))
            {
                $form=Zend_Registry::get('authForm');
            } else 
            {
                $form=new Application_Form_Login();
            }
            
            $this->view->placeholder('authform')->append($form);
            
            if (Zend_Registry::get('config')->user->register)
            {
                $this->view->placeholder('authform')->append('<a href="'.$this->view->fixUrl('user/register').'">'.Zend_Registry::get('locale')->_("Sign Up").'</a>');
                $this->view->placeholder('authform')->append('<a href="'.$this->view->fixUrl('user/recover').'">'.Zend_Registry::get('locale')->_("Forgot your password ?").'</a>');
            }
        } else 
        {
            $this->view->placeholder('authform')->append('<h3><a href="'.$this->view->baseUrl('user').'">'.$user.'</a></h3>');
            $this->view->placeholder('authform')->append('<div class="static">'.Zend_Registry::get('locale')->_('Role').': '.$user->getRole().'</div>');
            $this->view->placeholder('authform')->append('<div class="static">'.Zend_Registry::get('locale')->_('Status').': '.$user->getStatus().'</div>');
            
            if ($user->isNotActive())
            {
                $this->view->placeholder('authform')->append('<a href="'.$this->view->fixUrl('user/confirm').'">'.Zend_Registry::get('locale')->_("Didn't recieve confirmation message ?").'</a>');
            }
            if (!$user->isBlocked())
            {
                $this->view->placeholder('authform')->append('<a href="'.$this->view->fixUrl('user/edit').'">'.Zend_Registry::get('locale')->_('Edit profile').'</a>');
            }
            if ($user->canView())
            {
                $this->view->placeholder('authform')->append('<a href="'.$this->view->fixUrl('user/list').'">'.Zend_Registry::get('locale')->_('All users').'</a>');
            }
            $this->view->placeholder('authform')->append('<a href="'.$this->view->fixUrl('user/logout').'">'.Zend_Registry::get('locale')->_('Logout').'</a>');
        }
        
        $output=$this->view->placeholder('authform');
        
        return $output;
    }
}